#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
char str[maxn];
bool vis[maxn];
int main(void){
   ///cin.tie(0);std::ios::sync_with_stdio(false);
   LL t;cin>>t;
   while(t--){
      LL n;cin>>n;
      cin>>(str+1);
      for(LL i=0;i<=n+10;i++) vis[i]=0;
      bool ok=0;
      LL r=0;
      for(LL i=1;i<=n;i++){
          if(!ok&&str[i]=='M'){
             ok=1;
          }
          else if(ok&&str[i]=='T') {r=i;break;}
      }
      if(!r){
        cout<<"NO"<<"\n";continue;
      }
      LL num1=0;LL num2=0;
      for(LL i=1;i<=n;i++){
         if(str[i]=='T') num1++;
         else num2++;
      }
      bool f=1;
      if(num1!=num2*2){
        f=0;
      }
      if(f==0){
         cout<<"NO"<<"\n";
         continue;
      }
   ///   debug(r);
      LL l=1;
      bool flag=1;
      for(LL i=1;i<=n;i++){
          /// cout<<"fuck"<<"\n";
          if(str[i]=='M'){
          ///  debug(l);debug(r);
            while((l<=i) &&(vis[l]||str[l]=='M') ) l++;
            while((r<=n)&&(l>=r||vis[r]||str[r]=='M') ) r++;
            debug(l);debug(r);
            if(l<i&&r>i&&str[l]=='T'&&str[r]=='T'){
                vis[i]=vis[l]=vis[r]=true;
               /// l++;r++;
            }
            else{
                flag=0;break;
            }
          }
      }
      ///debug(flag);
     /// cout<<"f"<<"\n";
      for(LL i=1;i<=n;i++){
          if(!vis[i]) flag=0;
      }
      if(flag){
         cout<<"YES"<<"\n";
      }
      else{
         cout<<"NO"<<"\n";
      }
   }
   return 0;
}
